<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%-- <%@include file="common.jsp" %> --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>库存报表</title>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.10.2.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/bootstrap/dist/js/bootstrap.js"></script>
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/plugins/layui/css/layui.css"
	media="all" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/css/bootstrap-datetimepicker.min.css">
<script src="${pageContext.request.contextPath }/js/toastr.min.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath }/css/toastr.min.css">
<script
	src="${pageContext.request.contextPath }/bootstrap-table/dist/bootstrap-table.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/plugins/layui/layui.js"></script>
<link
	href="${pageContext.request.contextPath }/bootstrap-table/dist/bootstrap-table.css"
	rel="stylesheet" />
<script
	src="${pageContext.request.contextPath }/bootstrap-table/src/locale/bootstrap-table-zh-CN.js"></script>
<script
	src="${pageContext.request.contextPath }/js/bootstrap-datetimepicker.min.js"></script>
<script
	src="${pageContext.request.contextPath }/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/highcharts.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/validator.js"></script>
<script type="text/javascript">
$(function () {
	$('#d1').hide();
	$('#d2').hide();
	$('#d3').hide();

    //1.初始化Table
    var oTable = new TableInit();
    oTable.Init();

    //2.初始化Button的点击事件
    var oButtonInit = new ButtonInit();
    oButtonInit.Init();
	//初始化提示框位置
	toastr.options.positionClass = 'toast-top-center';
});

var TableInit = function () {
    var oTableInit = new Object();
    //初始化Table
    oTableInit.Init = function () {
        $('#tb_departments').bootstrapTable({
            url: '${pageContext.request.contextPath }/lcstock/selectfycx.do',
            method: 'get',                      //请求方式（*）
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            sortable: false,                     //是否启用排序
            sortOrder: "asc",                   //排序方式
            queryParams: oTableInit.queryParams,//传递参数（*）
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber:1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10,20,30],        //可供选择的每页的行数（*）
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: true,
            showColumns: true,                  //是否显示所有的列
            showRefresh: true,                  //是否显示刷新按钮
            minimumCountColumns: 2,             //最少允许的列数
            clickToSelect: true,                //是否启用点击选中行
            height:597,                         //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "id",                     //每一行的唯一标识，一般为主键列
            showToggle:true,                    //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            columns: [ {
				checkbox : true
			},{
				field : 'ssck',
				title : '所属仓库'
			}, {
				field : 'product.cartype',
				title : '车种'
			}, {
				field : 'product.name',
				title : '品名'
			}, {
				field : 'product.num',
				title : '品编'
			}, {
				field : 'product.color',
				title : '颜色'
			},{
				field : 'beginnum',
				title : '初期库存'
			}, {
				field : 'monthcome',
				title : '本月入库'
			}, {
				field : 'monthgo',
				title : '本月出库'
			}, {
				field : 'num',
				title : '库存数量'
			}, {
				field : 'product.remark5',
				title : '最低安全库存量'
			}]
        });
        $('#tb_orders').bootstrapTable({
            url: '${pageContext.request.contextPath }/maStock/maStock_list.do',
            method: 'get',                      //请求方式（*）
            toolbar: '#toolbarms',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            sortable: false,                     //是否启用排序
            sortOrder: "asc",                   //排序方式
            queryParams: oTableInit.queryParams,//传递参数（*）
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10,20,30],        //可供选择的每页的行数（*）
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: true,
            showColumns: false,                  //是否显示所有的列
            showRefresh: false,                  //是否显示刷新按钮
            minimumCountColumns: 2,             //最少允许的列数
            clickToSelect: true,                //是否启用点击选中行
            height: 488,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
            showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
            detailView: false,
            columns: [{
				checkbox : true
			},{

				title : '所属仓库',
                formatter:function () {
                    return "资材库"
                }
			}, {
				field : 'remark2',
				title : '车种'
			}, {
				field : 'name',
				title : '物料名称'
			},{
				field : 'color',
				title : '颜色'
			},{
				field : 'wbeginnum',
				title : '初期库存',
                formatter:function () {
                    return "329"
                }
			}, {
				field : 'wmonthcome',
				title : '本月入库',
                formatter:function () {
                    return "324"
                }
			}, {
				field : 'wmonthgo',
				title : '本月出库',
                formatter:function () {
                    return "853"
                }
			}, {
                field : 'csum',
				title : '库存数量'
			}, {
                field : 'remark7',
                title : '最低安全库存量'
            }, {
                field : 'remark8',
                title : '最高安全库存量'
            }]
        });
    };

    //得到查询的参数
    oTableInit.queryParams = function (params) {
    	var aa = $('#invenType').val();
    	
        var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            limit: params.limit,   //页面大小
            offset: params.offset,  //页码
            iscw: aa,
            name: $.trim($("#namee").val()),
            ssck: $.trim($("#ssckk").val()),
            car: $.trim($("#carr").val())
        };
        return temp;
    };
    return oTableInit;
};


var ButtonInit = function () {
    var oInit = new Object();
    var postdata = {};

    oInit.Init = function () {
        //初始化页面上面的按钮事件
    };

    return oInit;
};

function search() {
	//1 产品   2 物料
	var aa = $('#invenType').val();
	if (aa==1) {
		$('#d1').show();
		$('#d2').hide();
		$('#d3').hide();
		$('#tb_departments').bootstrapTable('refresh');
		
	} else if (aa==2) {
		$('#d2').show();
		$('#d1').hide();
		$('#d3').hide();
		$('#tb_orders').bootstrapTable('refresh');
		
	} else if (aa==0) {
		$('#d2').hide();
		$('#d1').hide();
		$('#d3').hide();
	};
	
}

//报表按钮
function baobiao(){	
	
		document.getElementById("d3").style.display="block"; 
		$('#d2').hide();
		$('#d1').hide();
		var aa = $('#invenType').val();
		//1产品  2物料
		if(aa == 0){
			toastr.warning("请选择仓库类型!");
		}else{
			
			$.ajax({ 
			      type: "post",  
			      url: "${pageContext.request.contextPath }/lcstock/selectBB.do",  
			      data: "type="+aa,
			      success:function(data){
			    	  var dataObj=eval("("+data+")");
				       if(aa == 1){
				    	   
				    	   var cname = [];//产品名称
				    	   var cqnum = [];//初期库存
				    	   var byrknum = [];//本月入库
				    	   var bycknum = [];//本月出库
				    	   var kcnum = [];//库存数量
				    	 /*   var aqnum = []; *///安全库存
				    	  
				    	   $.each(dataObj, function(index,values){ // 解析出data对应的Object数组 
				    		   $.each(values,function(index2,value){ // 遍历Object数组 ，每个对象的值存放在value ，index2表示为第几个对象 
				    		   		cname[index2]   =  value.product.name; //把产品名称放进数组中
				    		   		cqnum[index2]   =  Number(value.beginnum); //把初期库存放进数组中
				    		   		byrknum[index2] =  Number(value.monthcome); //把本月入库放进数组中
				    		   		bycknum[index2] =  Number(value.monthgo); //把本月出库放进数组中
				    		   		kcnum[index2]   =  Number(value.num); //把库存数量放进数组中
				    		   		/* aqnum[index2]   =  Number(value.safetynum); */ //把安全库存放进数组中
				    		   }); 
				    		});
				    		  
				   	    $('#d3').highcharts({
					        chart: {
					            type: 'column'
					        },
					        title: {
					            text: '按仓库划分库存数量'
					        },
					        xAxis: {
					            categories: cname
					        },
					        yAxis: {
					            allowDecimals: false,
					            min: 0,
					            title: {
					                text: '库存数量'
					            }
					        },
					        tooltip: {
					            formatter: function () {
					                return '<b>' + this.x + '</b><br/>' +
					                    this.series.name + ': ' + this.y + '<br/>' +
					                    '总量: ' + this.point.stackTotal;
					            }
					        },
					        plotOptions: {
					            column: {
					                stacking: 'normal'
					            }
					        },
					        series: [{
					            name: '初期库存',
					            data: cqnum,
					            stack: 'male'
					        }, {
					            name: '本月入库',
					            data: byrknum,
					            stack: 'male'
					        }, {
					            name: '本月出库',
					            data: bycknum,
					            stack: 'male'
					        }, {
					            name: '库存数量',
					            data: kcnum,
					            stack: 'male'
					        }]
					    });
				   	    
				       }else if(aa == 2){
				    	   
				    	   var wcname = [];//物料名称
				    	   var wcqnum = [];//初期库存
				    	   var wbyrknum = [];//本月入库
				    	   var wbycknum = [];//本月出库
				    	   var wkcnum = [];//库存数量
				    	   /* var waqnum = []; *///安全库存
				    	  
				    	   $.each(dataObj, function(index,values){ // 解析出data对应的Object数组 
				    		   $.each(values,function(index2,value){ // 遍历Object数组 ，每个对象的值存放在value ，index2表示为第几个对象
				 
				    		   		wcname[index2]   =  value.materiel.name; //把物料名称放进数组中
				    		   		
				    		   		wcqnum[index2]   =  Number(value.wbeginnum); //把初期库存放进数组中
				    		   		wbyrknum[index2] =  Number(value.wmonthcome); //把本月入库放进数组中
				    		   		wbycknum[index2] =  Number(value.wmonthgo); //把本月出库放进数组中
				    		   		wkcnum[index2]   =  Number(value.wnum); //把库存数量放进数组中
				    		   		/* waqnum[index2]   =  Number(value.wsafetynum); */ //把安全库存放进数组中
				    		   }); 
				    		});
				    		  
				   	    $('#d3').highcharts({
					        chart: {
					            type: 'column'
					        },
					        title: {
					            text: '按仓库划分库存数量'
					        },
					        xAxis: {
					            categories: wcname
					        },
					        yAxis: {
					            allowDecimals: false,
					            min: 0,
					            title: {
					                text: '库存数量'
					            }
					        },
					        tooltip: {
					            formatter: function () {
					                return '<b>' + this.x + '</b><br/>' +
					                    this.series.name + ': ' + this.y + '<br/>' +
					                    '总量: ' + this.point.stackTotal;
					            }
					        },
					        plotOptions: {
					            column: {
					                stacking: 'normal'
					            }
					        },
					        series: [{
					            name: '初期库存',
					            data: wcqnum,
					            stack: 'male'
					        }, {
					            name: '本月入库',
					            data: wbyrknum,
					            stack: 'male'
					        }, {
					            name: '本月出库',
					            data: wbycknum,
					            stack: 'male'
					        }, {
					            name: '库存数量',
					            data: wkcnum,
					            stack: 'male'
					        }]
					    });
				       
	   				}
			      }
			});
		}
	}
</script>
<script type="text/javascript">
 $(function () {
	$(".form_datetime").datetimepicker({
	 format: "yyyy-mm-dd",
	 autoclose: true,
	 todayBtn: true,
	 todayHighlight: true,
	 showMeridian: true,
	 pickerPosition: "bottom-left",
	 language: 'zh-CN',//中文，需要引用zh-CN.js包
	 startView: 2,//月视图
	 minView: 2//日期时间选择器所能够提供的最精确的时间选择视图
	 });
 });
</script>
</head>
<body>
	<div class="panel-body" style="padding-bottom:0px;">
        <div class="panel panel-default">
            <div class="panel-heading">查询条件</div>
            <div class="panel-body">
                <form id="formSearch" class="form-horizontal">
                    <div class="form-group" style="margin-top:15px">
                       <label class="control-label col-sm-1" for="txt_search_departmentname">仓库</label>
                        <div class="col-sm-3">
                            <select class="form-control" id="invenType" name="invenType">
								<option value="0">-- 请选择类型 --</option>
								<option value="1">产品</option>
								<option value="2">物料</option>
							</select>
                        </div>
                        <label class="control-label col-sm-1" for="txt_search_namee">名称(物料/产品)</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control"   id="namee">
                        </div>
                        <label class="control-label col-sm-1" for="txt_search_ssckk">所属仓库</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control"   id="ssckk">
                        </div>
                        <label class="control-label col-sm-1" for="txt_search_carr">车种</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control"  id="carr">
                        </div>
                        <div class="col-sm-4" style="text-align:left;">
                            <button type="button" style="margin-left:50px" id="btn_query" 
                            	class="btn btn-primary" onclick="search()">查询</button>
                            <button type="button" style="margin-left: 10px" id="btn_clear"
								class="btn btn-primary" onclick="baobiao()">报表</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>  
        
            
        
        <div id="d1"><table id="tb_departments"></table>
        
        	<div id="toolbar" class="btn-group">
            <button id="btn_add" type="button" class="btn btn-default" onclick="douploadModal()">
                <span class="glyphicon glyphicon-bullhorn" aria-hidden="true"></span>导入
            </button>
            <button id="btn_delete" type="button" class="btn btn-default" onclick="doExportall()">
                <span class="glyphicon glyphicon-export" aria-hidden="true"></span>导出所有
            </button>
            
            
            <script type="text/javascript">
	        	function doExport() {
	        		Ewin.confirm({message : "确认导出所有数据吗？"}).on(
    					function(e) {
   						if (!e) {return;}
						window.location.href="${pageContext.request.contextPath}/lcstock/doExportP.do"; 
					})
				}
	        	function doExportall() {
	        		Ewin.confirm({message : "确认导出所有数据吗？"}).on(
    					function(e) {
   						if (!e) {return;}
						window.location.href="${pageContext.request.contextPath}/lcstock/doExportallP.do"; 
					})
				}
	        	
	        	function douploadModal() {
	        		$('#uploadModal').modal(open);
	        		//清空表单
	        		document.getElementById("importForm").reset();
	        	}
	        	
	        	function uploadBtn() {
	        		 var fileName = $("#fileInput").val();
	        		 if (fileName.length > 0) {
	        		     var formData = new FormData($("#importForm")[0]);  
	        		     $.ajax({  
	        		          url: '${pageContext.request.contextPath}/lcstock/uplodeFileP.do' ,  
	        		          type: 'post',  
	        		          data: formData,
	        		          async: false,  
	        		          cache: false,  
	        		          contentType: false,  
	        		          processData: false,  
	        		          success: function (data) { 
	        		        	  if (data == 1) {
	        		        		  toastr.success("文件导入成功！");
	        		        		  setTimeout(function() {//使用setTimeout()方法设定定时2000毫秒
	        		        		    $('#uploadModal').modal('hide'); 
	        		        		   $('#tb_departments').bootstrapTable('refresh'); 
	        						  },1000);
	        		        	  }else if(data == -1){
	        		        		  toastr.warning("导入的数据不符合导入条件（产品品编找不到对应的产品）！");  
	        		        	  }else{
	        		        		  toastr.warning("文件格式异常，文件导入失败！");  
	        		        	  }
	        		          },  
	        		          error: function (data) {
	        		        	  toastr.error("文件格式异常，文件导入失败！");  
	        		          }  
	        		     }); 
	        		 }else{
	        			 toastr.warning("上传文件为空，请选择要导入的文件！");  
	        		}
	        	}
	        	
            </script>
        </div>	
        </div>
        <div id="d2"><table id="tb_orders"></table>
        	  <div id="toolbarms" class="btn-group">
	            <button id="btn_enter" type="button" class="btn btn-default">
	                <span aria-hidden="true" class="glyphicon glyphicon-import"></span>导入
	            </button>
    		</div>
        </div> 
        <div id="d3"><table id="tb_orderss"></table></div>
    </div>
    
    
    
    
    
    
        
        
        
        <div id="d1"><table id="tb_departments"></table></div>
        <div id="d2"><table id="tb_orders"></table></div> 
        <div id="d3"><table id="tb_orderss"></table></div>
    
    
    
    
    
    
    
    
    <!--导入数据操作层-->
    <div id="uploadModal" class="modal fade bs-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header bg-primary">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">文件导入</h4>
                </div>
                <div class="modal-body">
                    <div style="text-align:right;padding:5px">
                        <a href="${pageContext.request.contextPath }/datas/product.xls" onclick="javascript:Preview();">
                            <img alt="测试用户信息-模板" src="${pageContext.request.contextPath }/images/excel_alt_1.png" style="width: 20px;"/>
                            <span style="font-size:larger;font-weight:200;color:red">product-模板.xls</span>
                        </a>
                    </div>
                    <hr/>
                    <form id="importForm" method="post">
                        <div title="Excel导入操作" style="padding: 5px">
                            <%-- <input type="hidden" id="AttachGUID" name="AttachGUID" />
                             <input id="excelFile" type="file">--%>
                            <input type="file" id="fileInput" name="pic" accept=".xls,.xlsx">
                        </div>
                    </form>

                    <!--数据显示表格-->
                    <table id="gridImport" class="table table-striped table-bordered table-hover" cellpadding="0" cellspacing="0" border="0">
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="uploadBtn()">保存</button>
                </div>
            </div>
        </div>
    </div>
    
    <!--导入数据操作层-->
    <div id="importCb" class="modal fade bs-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header bg-primary">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">文件导入</h4>
                </div>
                <div class="modal-body">
                    <div style="text-align:right;padding:5px">
                        <a href="${pageContext.request.contextPath }/datas/MaStock.xls" onclick="javascript:Preview();">
                            <img alt="测试用户信息-模板" src="${pageContext.request.contextPath }/images/excel_alt_1.png" style="width: 20px;"/>
                            <span style="font-size:larger;font-weight:200;color:red">MaStock-模板.xls</span>
                        </a>
                    </div>
                    <hr/>
                    <form id="picImport" method="post">
                        <div title="Excel导入操作" style="padding: 5px">
                            <input type="file" id="pic" name="pic">
                        </div>
                    </form>

                    <!--数据显示表格-->
                    <table id="gridImport" class="table table-striped table-bordered table-hover" cellpadding="0" cellspacing="0" border="0">
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="SaveImport()">保存</button>
                </div>
            </div>
        </div>
    </div>
    
     <script type="application/javascript">
     
     
     $(function () {
         $("#btn_enter").click(function () {

             $("#importCb").modal("show");
         });
     });
        function SaveImport() {
            var picImport = new FormData($("#picImport")[0]);

            $.ajax({
                url: "${pageContext.request.contextPath}/maStock/maStock_import.do",
                type: 'post',
                data: picImport,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    var result=eval("("+data+")");
                    if(result.success){

                        $("#importCb").modal("hide");
                        $('#tb_orders').bootstrapTable('refresh');
                        toastr.success("操作成功");

                    }else{

                        toastr.error('操作失败!');
                        return;
                    }
                },
            });
        }
    </script>
</body>
</html>
